

if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
end

if ( CLIENT ) then

	SWEP.PrintName			= "Elites"			
	SWEP.Author				= "Counter-Strike"
	SWEP.Slot				= 1
	SWEP.SlotPos			= 1
	SWEP.IconLetter			= "s"
	
	killicon.AddFont( "weapon_elite", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
	
end

SWEP.HoldType			= "pistol"
SWEP.Base				= "weapon_cs_base2_ds"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel 			= "models/weapons/v_pist_elite.mdl"
SWEP.WorldModel 		= "models/weapons/w_pist_p228.mdl"

SWEP.Weight				= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false

SWEP.Primary.Sound			= Sound( "Weapon_Elite.Single" )
SWEP.Primary.Recoil			= 0.6
SWEP.Primary.Damage			= 8
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.011
SWEP.Primary.ClipSize		= 30
SWEP.Primary.Delay			= 0.1
SWEP.Primary.DefaultClip	= 150
SWEP.Primary.Automatic		= false
SWEP.Primary.Ammo			= "pistol"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"

SWEP.ViewModelFlip			= true

function SWEP:Reload()
	if self.Owner:KeyDown( IN_ATTACK ) then
		self.NeedToReload = true
		return
	end
	self.NeedToReload = false
	self.ViewModelFlip = true

	self.Weapon:DefaultReload( ACT_VM_RELOAD )
end

function SWEP:Deploy()
	self.ViewModelFlip = true
	self.Weapon:SetNextPrimaryFire( CurTime() + 1 )

	self.Weapon:SendWeaponAnim( ACT_VM_DRAW )

	return true
end

function SWEP:Think()
	if SERVER and self.NeedToReload then
		self:Reload()
	end
	
	if self.Weapon:Clip1() < 1 and !self.Owner:KeyDown( IN_ATTACK ) and !self.AutoReloading then
		self:Reload()
		self.AutoReloading = true
		return
	end
	if self.Owner:KeyPressed(IN_ATTACK) then
		self.ViewModelFlip = !self.ViewModelFlip
	end

	if self.Weapon:Clip1() > 0 then
		self.AutoReloading = false
	end
end

function SWEP:PrimaryAttack()

	self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
	self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
	
	if !self:CanPrimaryAttack() or self.Owner:WaterLevel() > 2 or self.Weapon:Clip1() < 1 then return end

	local LastShootTime = self.Weapon:GetNetworkedFloat( "LastShootTime", 0 )
	local Crouch = ( self.Owner:Crouching() and self.Owner:OnGround() ) and 2 or 1
	
	self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone / math.Clamp( ( CurTime() - LastShootTime ) * 1.3 , 0.001, 1 ) / Crouch )
	
	if self.Owner:IsNPC() then return end

	self.Owner:ViewPunch( Angle( math.Rand( -0.5, -0.1 ) * self.Primary.Recoil, math.Rand( -0.5, 0.5 ) *self.Primary.Recoil, 0 ) )

	if ( (SinglePlayer() && SERVER) || CLIENT ) then
		self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
	end
end